/*
 * $Id$
 */

package corejs.rt;

import java.util.Map;


/**
 *
 * @author pengyu
 */
public class Bool extends Primitive {
   
   private boolean _bool;
   
   public final static Bool TRUE = new Bool(true);
   
   public final static Bool FALSE = new Bool(false);
   
   private Bool(final boolean bool) {
      _bool = bool;
      store("toString", new Invocable() {
         @Override
         public Value invoke(final ExecutionContext ec) {
            return Bool.this.toStr(); 
         }
      });
   }
   
   /**
    *
    * @param b
    * @return
    */
   public static Bool valueOf(final boolean b) {
      return b ? TRUE : FALSE;
   }
   
   /**
    *
    * @return
    */
   public boolean isTrue() {return _bool;}
   
   /**
    *
    * @return
    */
   @Override
   public Bool toBool() {return this;}
   
   // spec 9.3
   @Override
   public Number toNumber() {
      return _bool ? Int.ONE : Int.ZERO;
   }
   
   @Override
   public Str toStr() {
      return _bool ? Str.TRUE : Str.FALSE;
   }
   
   @Override
   public boolean equals(final Primitive y) {
      return this == y || toNumber().equals(y);
   }
   
   @Override public Str typeof() {return Str.BOOLEAN;};
}
